#3) 参考1.10的综合案例中的学生信息管理，
#来实现一个自动取款机的存取款模拟效果。要求有登陆和退出、查询余额、取钱，存钱等操作。

#c) 第三题共计35分，共计5个操作，每个操作7分。



accountList=[
{'name':'chen0', 'passWord':'10','amount':'100'},
{'name':'chen1', 'passWord':'12','amount':'100'},
{'name':'chen3', 'passWord':'12','amount':'100'},
{'name':'chen4', 'passWord':'13','amount':'100'}
]






#################################################

#登陆账号 
def n1LoadAccount():
    while True:
        loadName = input("输入账号：")
        loadPassword = input("输入mima：")

        vertical0 = []
        #n1key = -1

        for i in range(len(accountList)):

            vertical0.append(accountList[i]["name"])
            #print(vertical0)
            
            if (loadName == accountList[i]["name"]) and (loadPassword == accountList[i]["passWord"]):
                n1key =i
                return i
            
        if loadName in vertical0:
            print("账号密码错误，请重新输入：")
        else :
            print("账号不存在，请重新输入：")

        if input("输入1结束登陆，其他键继续登陆操作") == '1':
            return -1
        
       
        
#注册账号
def n1register():
    print("="*12,"账号注册")
    n1list = {}
    n1list["name"] = input("请输入新的账户名：")
    n1list["passWord"] = input("请输入新密码：")
    n1list["amount"] = "0"
    
    for i in range(len(accountList)):
        if n1list["name"] == accountList[i]["name"]:
            if n1list["passWord"] == accountList[i]["passWord"]:
                print("此账户和密码存在，无需再注册")
                n1r1 = 1 
                break
            else:
                n1r1 = 0
        else:
            n1r1 = 0

    if n1r1 == 1:
        pass
    else:
        accountList.append(n1list)
        print("成功注册",n1list["name"],n1list["passWord"],"请保存")



#登陆成功，存取钱操作
def accessLoad(ac): #对序列号为ac的账号进行存取款
    

    while True:
        print("="*12,"*登陆成功","="*14)
        print("{0:1} {1:15} {2:15}".format(" ","1. 取钱","2. 存钱"))
        print("{0:1} {1:13} {2:15}".format(" ","3. 余额查询","4. 退出账户"))
        print("="*40)
        
        akey = input("输入需要执行的操作:")
        
        if akey == '1':
            print("="*12,"取钱","="*14)

            a1 = input("请输入取钱金额：")

            while a1 > accountList[ac]["amount"]:
                a1 = input("账户余额不足，请输入取钱金额：")

            accountList[ac]["amount"] =  str(int(accountList[ac]["amount"])-int(a1))
            print("本次操作取出金额为:"+a1)
            
            

        elif akey == '2':
            print("="*12,"存钱","="*14)

            a1 = input("请输入取钱金额：")

            accountList[ac]["amount"] =  str(int(accountList[ac]["amount"])+int(a1))
            print("本次操作存入金额为:"+a1)
            


        elif akey == '3':
            print("="*12,"余额查询","="*14)

            print("账户余额为："+accountList[ac]["amount"])


        elif akey == '4':
            print("="*12,"退出账户","="*14)

            break


while True:

    print("="*12,"自动取款机的存取款模拟","="*14)
    print("{0:1} {1:13} {2:15}".format(" ","1. 登陆账号","2. 注册账号"))
    print("="*40)



    key = input("请输入对应选项前的数字：")

    if key =="1":
        #lis 为账户序列号
        lis = n1LoadAccount()

        if lis>=0 and lis <=len(accountList):      
            accessLoad(lis)
            

    elif key == "2":
        #账号注册
        while True:
            n1register()

            a = input("按1继续注册，按其他键结束：")

            if a == 1:
                pass
            else:
                break
    else:
        print("======== 无效的键盘输入！ ==========")


    print()
    
        
            
        
            
        
        

            

                    
                
                
            
            

        





        


'''

'''




